home *** CD-ROM | disk | FTP | other *** search
- /* GatherTimes ---------------------------------------------------
- *
- * Demo precision timing experiments.
- * We collect raw time measurements, then call the
- * TStats package to display results.
- *
- * For your functions, you must:
- * 1) #include their headers.
- * 2) #define Arglist, Fun1, Fun2 macros with the specs
- * for your functions (as shown for Foo and FooBar).
- * 3) declare and init data needed by your functions in main.
- * 4) init anything else your functions need before the
- * Loop macro (as we set arg1 = arg2 = 1).
- *
- * You need not modify anything else except the testing
- * parameters {Which, Precision, Accuracy}.
- *
- * Copyright (c) 1993 Bill Karsh.
- * All rights reserved.
- *
- */
-
-
- #pragma options( !check_ptrs )
-
-
- #include "TestFuncs.h"
- #include "TStats.h"
- #include <Timer.h>
-
-
-
-
-
-
- // competitors to test
-
- #define First 1
- #define Second 2
- #define Both 3
-
- #define Which Both
-
- #define ArgList ( &arg1, &arg2 )
- #define Fun1 Foo
- #define Fun2 FooBar
-
- //----------------------------------------------------------------
-
- // timing parameters
-
- #define MaxNeg 0x80000000
-
- #define Precision 100
- #define Accuracy 1000 // must be > 0
-
- //----------------------------------------------------------------
-
- // timing macros and glue
-
- static void Overhead( ... )
- {
- // always empty
- }
-
- // call once to fill caches
- // call repeatedly to gather timing data
-
- #define Loop( F, T ) \
- F ArgList; \
- \
- tmt.tmWakeUp = tmt.tmReserved = 0L; \
- InsXTime( &tmt ); \
- PrimeTime( &tmt, MaxNeg ); \
- for( prc = 0; prc < Precision; prc++ ) { \
- F ArgList; \
- } \
- RmvTime( &tmt ); \
- T = tmt.tmCount - MaxNeg
-
- #define WAIT \
- Delay( 20, &dum ); while( !Button() )
-
- //----------------------------------------------------------------
-
-
-
-
-
-
- void main( void )
- {
- //--- specific args for your functions
-
- long arg1, arg2;
-
- //--- timer args
-
- long prc, acc;
- long time1 = 0, time2 = 0, timeOv;
- long dum;
- TMTask tmt;
- Boolean done;
-
- // initializations
-
- InitGraf( &thePort );
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs( nil );
- InitCursor();
-
- tmt.tmAddr = nil;
-
- TSInit( nil, Accuracy, Accuracy );
-
- //----------------------------------------------------------------
-
- for( acc = 0; acc < Accuracy; acc++ ) {
-
- #if Which & First
- // init data for your Fun1
- arg1 = 1;
- arg2 = 1;
-
- Loop( Fun1, time1 );
- #endif
-
-
- #if Which & Second
- // init data for your Fun2
- arg1 = 1;
- arg2 = 1;
-
- Loop( Fun2, time2 );
- #endif
-
- Loop( Overhead, timeOv );
- if( time1 > timeOv ) time1 -= timeOv;
- if( time2 > timeOv ) time2 -= timeOv;
-
- TSAccumulate( time1, time2 );
- }
-
- //----------------------------------------------------------------
-
- TSRawPlots();
- TSStats( kRaw );
- WAIT;
-
- TSRawHistos();
- WAIT;
-
- done = TSFilterMode( kRaw );
- TSStats( kWork );
- WAIT;
-
- if( !done ) {
- do {
- done = TSFilterMode( kWork );
- TSStats( kWork );
- WAIT;
- } while( !done );
- }
-
- TSDispose();
- }
-
-
-
-